<template>
  <van-button
    :icon="value ? 'star' : 'star-o'"
    :class="{ text: value }"
    :loading="loading"
    @click="changeCollect"
  />
</template>

<script>
// 导入 收藏 取消收藏 接口
import { collecArtcle, cancleCollecArtcle } from '@/api/user.js'
export default {
  name: 'collectIndex',
  props: {
    value: {
      type: Boolean,
      required: true
    },
    art_id: {
      type: [Number, String],
      required: true
    }
  },
  data() {
    return {
      loading: false
    }
  },
  created() {},
  methods: {
    async changeCollect() {
      this.loading = true
      console.log(this.value)
      if (this.value) {
        // 表示 已经收藏
        await cancleCollecArtcle(this.art_id)
        this.$emit('input', !this.value)
        this.$toast.success('我将继续努力！')
      } else {
        //   表示 没有收藏
        await collecArtcle(this.art_id)
        this.$emit('input', !this.value)
        this.$toast.success('感谢喜欢！')
      }
      this.loading = false
    }
  },
  computed: {},
  watch: {},
  components: {}
}
</script>

<style lang="less" scoped>
.text {
  color: #ffbf1a;
}
</style>
